package cn.book.serves;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import cn.book.dao.BookDao;
import cn.book.entity.Book;
import cn.book.factory.SqlSessionFactoryUtil;

public class BookServe {
	SqlSession sqlSession=null;
	/**
	 * 添加图书
	 * @param bookname
	 * @param suthor
	 * @param publish
	 * @param price
	 * @param currcount
	 * @param picture
	 * @return
	 */
	public boolean addBook(String bookname,String suthor,String publish,int price,int currcount,String picture){
		sqlSession=SqlSessionFactoryUtil.getSqlSession();
		BookDao bookDao=sqlSession.getMapper(BookDao.class);
		boolean flag=bookDao.addBook(bookname, suthor, publish, price, currcount, picture);
		sqlSession.commit();
		return flag;
	}
	
	/**
	 * 查询全部的书籍信息
	 * @return
	 */
	public List<Book> queryBookList(){
		sqlSession=SqlSessionFactoryUtil.getSqlSession();
		BookDao bookDao=sqlSession.getMapper(BookDao.class);
		List<Book> list=bookDao.queryBookList();
		return list;
	}
	
	public List<Book> selectPublish(String publish){
		sqlSession=SqlSessionFactoryUtil.getSqlSession();
		BookDao bookDao=sqlSession.getMapper(BookDao.class);
		List<Book> list=bookDao.selectPublish(publish);
		return list;
	}
	
	public List<Book> selectCurrcount(int currcount){
		sqlSession=SqlSessionFactoryUtil.getSqlSession();
		BookDao bookDao=sqlSession.getMapper(BookDao.class);
		List<Book> list=bookDao.selectCurrcount(currcount);
		return list;
	}
	
	public boolean deleteBook(int bookid){
		sqlSession=SqlSessionFactoryUtil.getSqlSession();
		BookDao bookDao=sqlSession.getMapper(BookDao.class);
		boolean flag=bookDao.deleteBook(bookid);
		sqlSession.commit();
		return flag;
	}

}
